package com.ezops.gateway;

import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.ezops.dto.RemoteRequest;

/**
 * Works as a gateway to the messaging system.The reports request and response
 * is being handled by this class and provides a layer between app and MQ.
 * 
 * @author vgaurav
 * 
 */
@Component
public class EzopsRemoteGateway implements IEzopsRemoteGateway {

	@Autowired
	private MqSender sender;

	@Autowired
	@Qualifier("consumer")
	private MqListener listener;

	@Override
	public void sendRemoteRequest(RemoteRequest request,
			ResponseHandler handler) {
		Message message = MessageFactory.generateMessage(request);
		handler.setMessageIdentifierKey(request.getMessageIdentifierKey());

		// register for getting the response back.
		listener.register(handler);

		sender.send(message);

	}

}
